/**
 * @Company 
 * @Title: LoginController.java 
 * @Package com.jbinfo.qingcaowan.app.controller 
 * @author lizhenwei
 * @date 2016-07-11 下午1:06:21 
 * @version V1.0   
 */
package com.jbinfo.qingcaowan.app.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jbinfo.qingcaowan.base.dto.UserFullInfoDTO;
import com.jbinfo.qingcaowan.base.service.UserFullService;
import com.jbinfo.qingcaowan.user.service.UserService;
import com.jbinfo.qingcaowan.wx.WxInfo;

/**
 * @ClassName: LoginController
 * @Description: 登录controller
 * @author John Zhao
 */
@Controller
public class WxLoginController {

	private static final Logger LOG = LoggerFactory.getLogger(WxLoginController.class);
	
	@Resource
	private UserFullService userFullService;
	
	@Resource
	private UserService userService;
	
	// 验证并传出微信用户信息
	@RequestMapping(value = "/{client}/wxlogin")
	public @ResponseBody
	Object userLogin(@PathVariable("client") String client
			, WxInfo wxInfo
			, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		LOG.info("客户端为 " + client + " wxInfo：" + wxInfo);
		
		return userService.findWxRegByOpenId(wxInfo);
		
	}
	
	@RequestMapping(value = "/{client}/a/loginByWx")
	public @ResponseBody
	Object userLogin(@PathVariable("client") String client
			, UserFullInfoDTO userFullInfoDTO
			, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		LOG.info("客户端为 " + client + " userFullInfoDTO：" + userFullInfoDTO);
		
		response.setHeader("Access-Control-Allow-Origin"
				,"*"); // http://my.dj.com   http://www.dotnetdev.net
		
		response.setHeader("Access-Control-Allow-Credentials", "true");
		response.setHeader("Access-Control-Allow-Methods"
				,"PUT, GET, POST, DELETE, OPTIONS");
		response.setHeader("Access-Control-Allow-Headers"
				,"X-Requested-With,Content-Type,Authorization,Accept,Range,Origin");
		response.setHeader("Access-Control-Expose-Headers"
				,"Content-Range");
		response.setHeader("Access-Control-Max-Age","3600");
		
		return userFullService.getIndexByWx(userFullInfoDTO);
		
	}
}
